#! /usr/bin/env python3
# coding = uft-8

# 71 Simplify Path

class Solution(object):
    def _simplifyPath(self, path):
        split_list = path.split("/")
        stack = []
        for i in split_list:
            if i == ".":
                continue
            elif i == "..":
                if len(stack) > 0:
                    stack.pop()
            elif i != "":
                stack.append(i)
        return "/" + "/".join(stack)

    def simplifyPath(self, path):
        result = []
        pathList = path.split('/')
        for content in pathList:
            if content:
                if content == '..':
                    try:
                        result.pop()
                    except:
                        result = []
                elif content != '.':
                    result.append(content)
        return '/' + '/'.join(result)

s = Solution()
print(s._simplifyPath("///"))
